<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	    <%@page import="beans.*"%>
<%@page import="service.*"%>
<%@page import="java.util.*"%>
<!DOCTYPE html>
<html>
<head>
  <title>课表</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      margin: 0;
      padding: 20px;
    }
    
    table {
	border-collapse: collapse;
	width: 100%;
	margin-top: 20px;
	font-size: 16px;
}

table th, table td {
	border: 1px solid #ddd;
	padding: 8px;
	text-align: center;
}

table th {
	background-color: #f2f2f2;
	font-weight: bold;
}
    
    tr:hover {
      background-color: #eaeaea;
    }
    input[type="button"]{
	background-color: #4CAF50;
	border: none;
	color: #fff;
	padding: 10px 20px;
	text-align: center;
	text-decoration: none;
	display: inline-block;
	font-size: 16px;
	border-radius: 10px;
	cursor: pointer;
}
input[type="button"]:hover {
	background-color: #3e8e41;
}
#u{
display:none;
}
#ua{
position: fixed;
            width: 100%;
            height: 100%;
            left: 0;
            top: 0;
            background-color: rgba(0, 0, 0, 0.5);
            
}
label {
	display: inline-block;
	width: 200px;
	margin-bottom: 10px;
	font-weight: bold;
}
#ub{
margin: auto;
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	height:350px;
	width: 780px;
	background-color: white;
	text-align:center;
	border-radius: 10px;

}
#ub > select{
	width: 500px;
	border-radius: 10px;
	padding: 10px;
	border: none;
	background-color: #f2f2f2;
	margin-bottom: 10px;
	font-size: 16px;
}
#reason{
	width: 480px;
	border-radius: 10px;
	padding: 10px;
	border: none;
	background-color: #f2f2f2;
	margin-bottom: 10px;
	font-size: 16px;
}
input[type="date"] {
	width: 470px;
	border-radius: 10px;
	padding: 16px;
	border: none;
	background-color: #f2f2f2;
	margin-bottom: 10px;
}
  </style>
</head>
<body>
<%
doctorSchedulingService doctorSchedulingService=new doctorSchedulingService();
List<doctorSchedulingBean> list = doctorSchedulingService.getdoctorSchedulingbydoctor((String)session.getAttribute("id"));
mzService mzService = new mzService();
applicationService applicationService = new applicationService();
%>
		<table id="n">

			<thead>
				<tr>
					<th colspan="8">排班情况</th>
				</tr>
				<tr>
					<th style="display: none;">排班编号</th>
					<th>门诊编号-名称</th>
					<th>日期</th>
					<th>时间</th>
					<th>数量</th>
					<th>状态</th>
					<th>申请取消</th>
				</tr>
				
			</thead>
			<tbody>
			<%
				int i=0;
				while(list!=null&&i<list.size()){%>
					<tr class="table-row">
					<td style="display: none;"><%=list.get(i).getId() %></td>
					<td><%=list.get(i).getMzid() %>-<%=mzService.getRecord(list.get(i).getMzid()).getName() %></td>
					<td><%=list.get(i).getDate() %></td>
					<%if(list.get(i).getType().equals("100")){ %>
						<td>上午</td>
					<%}else if(list.get(i).getType().equals("010")){%>
						<td>下午</td>
					<%}else{ %>
						<td>晚上</td>
					<%} %>
					<td><%=list.get(i).getSum() %></td>
					<%if(applicationService.getRecordbyschid(list.get(i).getId())==null){ %>
					<td>正常</td>
					<%if(list.get(i).getDate().getTime()<=new Date().getTime()){ %>
					<td><input type="button" class="btn" value="申请取消" style="background-color:grey"disabled></td>
					<%}else{%>
					<td ><input type="button" class="btn"value="申请取消"></td>
					<%} %>
					<%}else if(applicationService.getRecordbyschid(list.get(i).getId()).getState().equals("待审核")){ %>
					<td>待审核</td>
					<%if(list.get(i).getDate().getTime()<=new Date().getTime()||"待审核".equals(applicationService.getRecordbyschid(list.get(i).getId()).getState())||"已取消".equals(applicationService.getRecordbyschid(list.get(i).getId()).getState())){ %>
					<td><input type="button" class="btn" value="申请取消" style="background-color:grey"disabled></td>
					<%}else{%>
					<td ><input type="button" class="btn"value="申请取消"></td>
					<%} %>
					<%}else{ %>
					<td><%=applicationService.getRecordbyschid(list.get(i).getId()).getState() %></td>
					<%if(list.get(i).getDate().getTime()<=new Date().getTime()||"待审核".equals(applicationService.getRecordbyschid(list.get(i).getId()).getState())||"已取消".equals(applicationService.getRecordbyschid(list.get(i).getId()).getState())){ %>
					<td><input type="button" class="btn" value="申请取消" style="background-color:grey"disabled></td>
					<%}else{%>
					<td ><input type="button" class="btn"value="申请取消"></td>
					<%} %>
					<%} %>
				</tr>
				<%i++;}
				%>
			</tbody>
		</table>
		<form id="u" action="../Main">
	<div id="ua">
	<div id="ub">
		<label>门诊：</label> <select id="mz" name="mz" disabled>
		</select><br> <label>日期：</label> <input type="date" id="date"
			name="date" disabled><br> <label>时间：</label> <select id="time"
			name="time" disabled><option value="100">上午</option>
			<option value="010">下午</option>
			<option value="001">晚上</option>
		</select><br> <label>挂号总数：</label> <select id="sum" name="sum" disabled>
		</select><br>
		<label>申请理由：</label><textarea id="reason" name="reason"></textarea>
		<br> <input type="hidden" name="action"
			value="applyCancel" /> <input type="text" id="schid"name="schid" value="" style="display:none;"><input id="ub1"type="button" value="提交"
			> <input id="ub2"type="button" value="取消">
	</div>
	</div>
	</form>
		<script type="text/javascript">
		var sum = document.getElementById("sum");
	   	for(var i=1;i<=100;i++){
	   		var option = document.createElement('option');
	   		option.innerHTML = i;
	   		option.value = i;
	   		sum.appendChild(option); 
	   	}
		document.querySelectorAll('.btn').forEach(item => {
      	  item.addEventListener('click', event => {
      		var u=document.getElementById('u');
      		u.style.display="block";
      		var row = event.target.closest(".table-row"); 
            var cells=row.querySelectorAll("td");
            var mz=document.getElementById('mz');
    		var date=document.getElementById('date');
            var time=document.getElementById('time');
            for (var i = mz.children.length - 1; i >= 0; i--) {
			    mz.removeChild(mz.children[i]);
		  }
            var option = document.createElement('option');
			option.innerHTML = cells[1].textContent;
			var z=0;
			while(cells[1].textContent[z]!='-'){
				z++;
			}
			option.value = cells[1].textContent.substring(0,z);
			mz.appendChild(option);
            date.value=cells[2].textContent;
   
            if(cells[3].textContent=="上午"){
            	time.value="100";
            }else if(cells[4].textContent=="下午"){
            	time.value="010";
            }else{
            	time.value="001";
            }
            sum.value=cells[4].textContent;
            var u=document.getElementById('u');
    		var ub1=document.getElementById('ub1');
            var ub2=document.getElementById('ub2');
            ub2.addEventListener('click', function () {
    	    	   u.style.display="none";
    	        });
            ub1.addEventListener('click',function(){
            	var reason=document.getElementById('reason');
            	if(reason.value==""){
            		alert("请填写完整信息");
            	}else{
            		u.submit();
         		   alert("申请成功");
            	}
    		  });
            var schid = document.getElementById('schid');
            schid.value=cells[0].textContent;
      	  })
		});
		
		</script>
</body>
</html>
